package com.acmetelecom.core;

import static com.acmetelecom.call.CallEventBuilder.asDateTime;
import static org.junit.Assert.assertTrue;

import org.joda.time.DateTime;
import org.junit.Test;

import com.acmetelecom.core.DaytimePeakPeriod;

public class OnPeakOffPeakTest {
	@Test
	public void testOffPeak() {
		DateTime start = new DateTime( asDateTime("02/12/11 4:00am") );
		DateTime end   = new DateTime( asDateTime("02/12/11 5:00am") );
		assertTrue( DaytimePeakPeriod.getOnPeakSeconds(start, end) == 0 );
		assertTrue( DaytimePeakPeriod.getOffPeakSeconds(start, end) == 60*60 );
	}
	
	@Test
	public void testOnPeak() {
		DateTime start = new DateTime( asDateTime("02/12/11 8:00am") );
		DateTime end   = new DateTime( asDateTime("02/12/11 9:00am") );
			assertTrue( DaytimePeakPeriod.getOnPeakSeconds(start, end) == 60*60 );
		assertTrue( DaytimePeakPeriod.getOffPeakSeconds(start, end) == 0 );
	}
	
	@Test
	public void testOverlap() {
		DateTime start = new DateTime( asDateTime("02/12/11 6:30am") );
		DateTime end   = new DateTime( asDateTime("02/12/11 7:15am") );
		assertTrue( DaytimePeakPeriod.getOnPeakSeconds(start, end) == 15*60 );
		assertTrue( DaytimePeakPeriod.getOffPeakSeconds(start, end) == 30*60 );
	}
	
	@Test
	public void testOverlapDay() {
		DateTime start = new DateTime( asDateTime("02/12/11 6:30am") );
		DateTime end   = new DateTime( asDateTime("05/12/11 7:15am") );
		
		/*
		 * 02 6:30am
		 * 03 ...
		 * 04 ...
		 * 05 7:15am
		 *
		 * 02 30*60 off, 12*60*60 on, 5*60*60 off
		 * 03 12*60*60 off, 12*60*60 on
		 * 04 12*60*60 off, 12*60*60 on
		 * 05 7*60*60 off, 15*60 on
		 */
		
		assertTrue( DaytimePeakPeriod.getOnPeakSeconds(start, end) == 12*60*60 + 12*60*60 + 12*60*60 + 15*60 );
		assertTrue( DaytimePeakPeriod.getOffPeakSeconds(start, end) == 30*60 + 5*60*60 + 12*60*60 + 12*60*60 + 7*60*60 );
	}
}
